<?php
if ( count( get_included_files() ) == 1 ) die( '---' );

class Droits
{
	var $competenceId;	
	
	var $groupeId;
	
	var $evaluateurId;

	var $courseCode;

	var $tableDroit;

	
    // Constructeur
    function Droits() 
    {
    	$this->competenceId = '';
    	$this->groupeId = '';
    	$this->evaluateurId = '';
	$this->courseCode = '';
	
	global $C2IPRATtables;    	
	$this->tableDroit = $C2IPRATtables['C2IPRATdroits'];
    }
    
    // Load 
    function load($competenceId=null,$groupeId=null,$evaluateurId=null,$courseCode=null)
    {
 
    	$sql = "SELECT *
		FROM `".$this->tableDroit."`
		WHERE 1=1";

	if ($competenceId)
	$sql .= " AND competenceId=$competenceId ";
	if ($groupeId)
	$sql .= " AND groupeId=$groupeId ";
	if ($evaluateurId)
	$sql .= " AND evaluateurId=$evaluateurId ";
	if ($courseCode)
	$sql .= " AND course_code=$courseCode ";

		$data = claro_sql_query_get_single_row($sql);

	   if( !empty($data) )
	   {
	   	$this->competenceId     	= $data['competenceId'];
	   	$this->groupeId      		= $data['groupeId'];
	   	$this->evaluateurId	   	= $data['evaluateurId'];
		$this->courseCode	   	= $data['courseCode'];
	   	
	   	return true;
	   }
	   else
	   return false;
    }
    
    
    // Save 
    function save()  
    {
	$this->delete();

	$sql = "INSERT INTO `".$this->tableDroit."` 
		SET competenceId = '".$this->competenceId."',
		    groupeId = '".$this->groupeId."',
		    evaluateurId = '".$this->evaluateurId."',
		    course_code = '".$this->courseCode."'";

	    if(claro_sql_query($sql))
	    {
		return true;
	    }
	    else
	    {
	        return false;
	    }
    }
    
    	 function delete()
	 {
	 	$sql = "DELETE FROM `".$this->tableDroit."` 
			WHERE competenceId = '".$this->competenceId."'
			AND groupeId = '".$this->groupeId."'
			AND evaluateurId = '".$this->evaluateurId."'
			AND course_code = '".$this->courseCode."'";
	 	return claro_sql_query($sql);
	 }
	 
	function peutEvaluerGrille ()
	{
		$sql_search = "SELECT * FROM `".$this->tableDroit."` WHERE evaluateurId = ".$this->evaluateurId." AND course_code = '".$this->courseCode."'";

		return claro_sql_query_affected_rows($sql_search);
	}
	
	function chercheGrille()
	{
		$sql = "SELECT grilleId FROM `".$this->tableDroit."` WHERE groupeId = ".$this->groupeId." AND course_code = '".$this->courseCode."'";
		return claro_sql_query_get_single_row($sql);
	}

	function chercheEvaluateurs()
	{
		$sql = "SELECT evaluateurId FROM `".$this->tableDroit."` WHERE groupeId = ".$this->groupeId." AND competenceId = ".$this->competenceId." AND course_code = '".$this->courseCode."'";
		return claro_sql_query_fetch_all_rows($sql);
	}


	/**
     * get id
     *
     * @author Pierre Raynaud
     * @return int
     */
	function getDroitId()
	{
		return (int) $this->droitId;
	}

     /**
     * set id
     *
     * @author Pierre Raynaud
     * @return int
     */
	function setDroitId($value)
	{
		$this->droitId = (int) $value;
	}
	
	/**
     * get competenceId
     *
     * @author Pierre Raynaud
     * @return string
     */
	function getCompetenceId()
	{
		return (int) $this->competenceId;
	}
	
	/**
     * set competenceId
     *
     * @author Pierre Raynaud
     * @param $value
     */
	function setCompetenceId($value)
	{
		$this->competenceId = $value;
	}
	
	/**
     * get groupeId
     *
     * @author Pierre Raynaud
     * @return string
     */
	function getGroupeId()
	{
		return $this->groupeId;
	}
	
	/**
     * set groupeId
     *
     * @author Pierre Raynaud
     * @param string $value
     */
	function setGroupeId($value)
	{
		$this->groupeId = (int) $value;
	}
	
	/**
     * get evaluateurId
     *
     * @author Pierre Raynaud
     * @return string
     */
	function getEvaluateurId()
	{
		return $this->evaluateurId;
	}
	
	/**
     * set evaluateurId
     *
     * @author Pierre Raynaud
     * @param string $value
     */
	function setEvaluateurId($value)
	{
		$this->evaluateurId = (int) $value;
	}
	
	/**
     * get courseCode
     *
     * @author Pierre Raynaud
     * @return string
     */
	function getCourseCode()
	{
		return $this->courseCode;
	}
	
	/**
     * set courseCode
     *
     * @author Pierre Raynaud
     * @param string $value
     */
	function setCourseCode($value)
	{
		$this->courseCode = $value;
	}
	


	/**
     * get masque
     *
     * @author Pierre Raynaud
     * @return string
     */
	function getMasque()
	{
		return $this->masque;
	}
	
	/**
     * set setmasque
     *
     * @author Pierre Raynaud
     * @param string $value
     */
	function setMasque($value)
	{
		$this->masque = (int) $value;
	}
}
?>
